package com.company.bookstore.mapper.book_module;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.company.bookstore.entities.book_module.BookImg;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author 姬深威
 * @since 2020-09-12
 */
@Component
public interface BookImgMapper extends BaseMapper<BookImg> {

    @Select("SELECT * FROM t_book_img WHERE fk_book_id=#{bookId}")
    List<BookImg> getBookImgByBookId(Integer bookId);

    @Delete("DELETE FROM t_book_img WHERE fk_book_id=#{bookId}")
    Integer deleteImgByBookId(Integer bookId);

    @Delete("DELETE FROM t_book_img WHERE id=#{imgId} AND fk_book_id=#{bookId}")
    Integer deleteImgByImgId(Integer bookId,Integer imgId);

    @Insert("INSERT INTO t_book_img (img_name,fk_book_id) VALUES(#{name},#{bookId})")
    Integer addImg(String name,Integer bookId);

    @Update("UPDATE t_book_img SET img_name=#{name},fk_book_id=#{bookId}")
    Integer updateImg(String name,Integer bookId);

}
